import multiprocessing, time


def process_share(data, key, value):
    data.update({key: value})
    print(f"进程【{multiprocessing.current_process().name}】"
          f"pid: {multiprocessing.current_process().pid}--"
          f"更新了: data={key}:{value}")


def main():
    manager = multiprocessing.Manager()  # 创建数据共享管理器
    process_dict = manager.dict(author="handuoduo")  # 创建字典对象

    process_a = multiprocessing.Process(
        target=process_share,
        args=(process_dict, 'python', '《Python开发实战》',)
    )
    process_b = multiprocessing.Process(
        target=process_share,
        args=(process_dict, 'java', '《Java程序语言设计开发》')
    )
    # 开始执行
    process_a.start()
    process_b.start()

    # 让子进程执行完毕
    process_a.join()
    process_b.join()

    # 从主进程查看内容
    print(f"【主进程】查看字典内容：{process_dict}")


if __name__ == '__main__':
    main()
